package com.briup.cms.web.controller;

import com.briup.cms.bean.Article;
import com.briup.cms.service.IArticleService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"文章资源操作接口"}, description = "集成增删改查")
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private IArticleService articleService;

    @ApiOperation("查询所有文章信息")
    @GetMapping("findAll")
    public Message findAll(){
        return MessageUtil.success(articleService.findAll());
    }

    @ApiOperation("查询所有文章信息（附带名称显示）")
    @GetMapping("findAllWithName")
    public Message findAllWithName(){
        return MessageUtil.success(articleService.findAllWithName());
    }

    @ApiOperation("更新或保存文章信息，当id为空时保存，否则更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Article article){ return MessageUtil.success(articleService.saveOrUpdate(article));
    }

    @ApiOperation("删除指定文章信息")
    @GetMapping("deleteById")
    public Message deleteById(@RequestParam @ApiParam(name = "id", value = "文章Id", required = true) Long id){
        articleService.deleteById(id);
        return MessageUtil.success("成功删除");
    }
}
